package org.weasel.business;

import java.sql.Time;
import java.util.ArrayList;

public class UserStory extends Item {
	private String id;
	private String name;
	private int businessValue;
	private Time estimatedTime;
	private Time usedTime;
	private int effort;
	private ArrayList<Developer> developers;
	private ArrayList<Task> tasks;
	
	public UserStory(String id, String name, int businessValue, Time estimatedTime, Time usedTime, int effort, ArrayList<Developer> developers, ArrayList<Task> tasks) {
		this.id = id;
		this.name = name;
		this.businessValue = businessValue;
		this.estimatedTime = estimatedTime;
		this.usedTime = usedTime;
		this.effort = effort;
		if(developers == null) {
			this.developers = new ArrayList<Developer>();
		} else {
			this.developers = developers;
		}
		if(tasks == null) {
			this.tasks = new ArrayList<Task>();
		} else {
			this.tasks = tasks;
		}
	}
	
	/***
	 * This method searches a developer in the list of developers and returns it;
	 * otherwise it returns null
	 * @param developerID
	 * @return
	 */
	public Developer getDeveloper(String developerID) {
		for (Developer developer : developers) {
			if(developer.getId().equals(developerID)) {
				return developer;
			}
		}
		return null;
	}
	
	public void addDeveloper(Developer developer) {
		developers.add(developer);
	}
	
	public void removeDeveloper(String developerID) {
		for (int i = 0; i < developers.size(); i++) {
			Developer tmp = developers.get(i);
			if(tmp.getId().equals(developerID)){
				developers.remove(i);
			}
		}
	}
	
	/***
	 * This method searches a task in the list of tasks and returns it;
	 * otherwise it returns null
	 * @param taskID
	 * @return
	 */
	public Task getTask(String taskID) {
		for (Task task : tasks) {
			if(task.getId().equals(taskID)) {
				return task;
			}
		}
		return null;
	}
	
	public void addTask(Task task) {
		tasks.add(task);
	}
	
	public void removeTask(String taskID) {
		for (int i = 0; i < tasks.size(); i++) {
			Task tmp = tasks.get(i);
			if(tmp.getId().equals(taskID)){
				tasks.remove(i);
			}
		}
	}

	public int getBusinessValue() {
		return businessValue;
	}

	public void setBusinessValue(int businessValue) {
		this.businessValue = businessValue;
	}

	public int getEffort() {
		return effort;
	}

	public void setEffort(int effort) {
		this.effort = effort;
	}

	public Time getEstimatedTime() {
		return estimatedTime;
	}

	public void setEstimatedTime(Time estimatedTime) {
		this.estimatedTime = estimatedTime;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ArrayList<Developer> getDevelopers() {
		return developers;
	}

	public void setDevelopers(ArrayList<Developer> responsibleDevelopers) {
		this.developers = responsibleDevelopers;
	}

	public ArrayList<Task> getTasks() {
		return tasks;
	}

	public void setTasks(ArrayList<Task> tasks) {
		this.tasks = tasks;
	}

	public Time getUsedTime() {
		return usedTime;
	}

	public void setUsedTime(Time usedTime) {
		this.usedTime = usedTime;
	}

	public String getId() {
		return id;
	}
}
